package com.dks.repository.impl;

import java.util.*;

import com.dks.dto.RewardDto;
import com.dks.mapper.RewardMapper;
import com.dks.models.Reward;
import com.dks.models.Student;
import com.dks.repository.IRewardRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class RewardRepository implements IRewardRepository {

    private RewardMapper rewardMapper;

    @Autowired
    public RewardRepository(final RewardMapper rewardMapperIn) {
        this.rewardMapper = rewardMapperIn;
    }

    @Override
    public Integer insert(Reward reward){
        return rewardMapper.insert(reward);
    }

    @Override
    public Integer update(Reward reward){
        return rewardMapper.update(reward);
    }

    @Override
    public Integer delete(Integer id){
        return rewardMapper.delete(id);
    }

    @Override
    public Reward select(Integer id){
        return rewardMapper.select(id);
    }

    @Override
    public Integer cntByMap(Map<String,Object> map){
        return rewardMapper.cntByMap(map);
    }

    @Override
    public List<Integer> getByMap(Map<String,Object> map){
        return rewardMapper.getByMap(map);
    }

    @Override
    public List<RewardDto> getByMapList(Map<String,Object> map){
        return rewardMapper.getByMapList(map);
    }

    @Override
    public Integer updateByCode(Reward reward){
        return rewardMapper.updateByCode(reward);
    }

    @Override
    public Reward selectByBfCode(String bfCode){
        return rewardMapper.selectByBfCode(bfCode);
    }


    @Override
    public ResultModel<Object> getTaskInfo(Integer parentId,Integer pageNum, Integer pageSize,Integer rewardType) {
        Map<String,Object> map = new HashMap<>();
        map.put("parentId",parentId);
        map.put("rewardType",rewardType);
        map.put("recStatus",0);
        Page p = PageHelper.startPage(pageNum, pageSize);
        List<RewardDto> rewardDtoList = rewardMapper.getByMapList(map);
        PageInfo<RewardDto> pageInfo = new PageInfo<>(pageNum, pageSize, p.getTotal(), p.getPages(), rewardDtoList);
        return Result.makeResult(ResultInfo.SUCCESS, pageInfo);

    }
}
